home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Think Class Libraries / SAT-TCL 1.0b2 / CGameClasses ƒ / CGameApp.p next >
Text File  |  1996-06-08  |  6KB  |  231 lines

  1. {****************************************************}
  2. {}
  3. {    CGameApp.p                                                                                                    }
  4. {}
  5. {    Application class, optimized to the needs of gameplay.                                    }
  6. {}
  7. {    Copyright © 1996 by Patrick C Hew. All rights reserved.                                }
  8. {}
  9. {****************************************************}
  10.  
  11.  
  12. unit CGameApp;
  13.  
  14. interface
  15.  
  16.     uses
  17.         TCL, GameIntf;
  18.  
  19. implementation
  20.  
  21.  
  22. {****************************************************}
  23. {}
  24. {    IGameApp                                                                                                        }
  25. {}
  26. {    Initializes a Game Application object.                                                                }
  27. {}
  28. {****************************************************}
  29.  
  30.     procedure CGameApp.IGameApp (extraMasters: Integer;
  31.                                     aRainyDayFund: Longint;
  32.                                     aCriticalBalance: Longint;
  33.                                     aToolboxBalance: Longint);
  34.  
  35.     begin { IGameApp }
  36.         IApplication(extraMasters, aRainyDayFund, aCriticalBalance, aToolboxBalance);
  37.  
  38.         { Start as a normal, everyday Macintosh application. }
  39.         isInGameMode := FALSE;
  40.  
  41.         { Default to not being friendly in animation mode. May want to store this as a preference. }
  42.         isBkgdFriendlyInGameMode := FALSE;
  43.     end; { IGameApp }
  44.  
  45.  
  46. {****************************************************}
  47. {}
  48. {    MakeSwitchboard                                                                                            }
  49. {}
  50. {    Creates the single Game Switchboard object used by the application.                }
  51. {    We store a pointer for our own use.                                                                }
  52. {}
  53. {****************************************************}
  54.  
  55.     procedure CGameApp.MakeSwitchboard;
  56.  
  57.         var
  58.             theSwitchboard: CGameSwitchboard;
  59.  
  60.     begin { MakeSwitchboard }
  61.         new(theSwitchboard);
  62.         theSwitchboard.IGameSwitchboard;
  63.         itsSwitchboard := theSwitchboard;
  64.         itsGameSwitchboard := theSwitchboard;
  65.     end; { MakeSwitchboard }
  66.  
  67.  
  68. {****************************************************}
  69. {}
  70. {    Idle                                                                                                                }
  71. {}
  72. {    It is expected that there is a Game Director, handling game animation etc.        }
  73. {    in its Dawdle method. This method streamlines the call during gameplay.        }
  74. {}
  75. {    It is assumed that during gameplay, the following hold :-                                }
  76. {    1    There are no memory emergencies to correct, so the Rainy Day memory    }
  77. {        fund does not need to be reset. It will, in any case, be reset when we            }
  78. {        leave game mode.                                                                                        }
  79. {    2    The Game Director is the gopher.                                                                 }
  80. {    3    Only the Game Director needs to receive a Dawdle method. Reasonable,        }
  81. {        unless you have a special director reporting to the Game Director; for        }
  82. {        instance, a window set up for controls.    In such a case, you may want        }
  83. {        to make the gopher send a Dawdle message to its supervisor.                        }
  84. {    4    There are no other Dawdle chores to perform.                                            }
  85. {}
  86. {****************************************************}
  87.  
  88.     procedure CGameApp.Idle (macEvent: EventRecord);
  89.  
  90.         var
  91.             maxSleep: LongInt;
  92.  
  93.     begin { Idle }
  94.         if not isInGameMode then begin
  95.             inherited Idle(macEvent);
  96.         end { if }
  97.         else begin
  98.             maxSleep := MAXLONGINT;
  99.  
  100.             gGopher.Dawdle(maxSleep);
  101.  
  102.             gSleepTime := maxSleep;
  103.         end; { else }
  104.     end; { Idle }
  105.  
  106.  
  107. {****************************************************}
  108. {}
  109. {    Process1Event                                                                                                }
  110. {}
  111. {    Streamlined processing of events during gameplay.                                        }
  112. {}
  113. {    It is assumed that during gameplay, the following hold :-                                }
  114. {    1    The desktop does not need to be cleaned up. This holds if there are no            }
  115. {        floating windows.                                                                                        }
  116. {    2    There are no urgent chores to be performed.                                                }
  117. {    3    There is no switching to or from desk accessories.                                    }
  118. {}
  119. {****************************************************}
  120.  
  121.     procedure CGameApp.Process1Event;
  122.  
  123.     begin { Process1Event }
  124.         if not isInGameMode then begin
  125.             inherited Process1Event;
  126.         end { if }
  127.         else begin
  128.             itsSwitchboard.ProcessEvent;
  129.         end; { else }
  130.     end; { Process1Event }
  131.  
  132.  
  133. {****************************************************}
  134. {}
  135. {    DoCommand                                                                                                    }
  136. {}
  137. {    Turn off game mode before quitting.                                                                 }
  138. {}
  139. {****************************************************}
  140.  
  141.     procedure CGameApp.DoCommand (theCommand: LongInt);
  142.  
  143.     begin { DoCommand }
  144.         if theCommand = cmdQuit then begin
  145.             isInGameMode := FALSE;
  146.             itsGameSwitchboard.SetBackgroundFriendly(TRUE);
  147.         end; { if }
  148.         inherited DoCommand(theCommand);
  149.     end; { DoCommand }
  150.  
  151.  
  152. {****************************************************}
  153. {}
  154. {    GetInGameMode                                                                                                }
  155. {}
  156. {    Return whether or not we are in game mode.                                                    }
  157. {}
  158. {****************************************************}
  159.  
  160.     function CGameApp.GetInGameMode: Boolean;
  161.  
  162.     begin { GetInGameMode }
  163.         GetInGameMode := isInGameMode;
  164.     end; { GetInGameMode }
  165.  
  166.  
  167. {****************************************************}
  168. {}
  169. {    BeginGameMode                                                                                        }
  170. {}
  171. {    Configure for fast event processing.                                                                }
  172. {}
  173. {****************************************************}
  174.  
  175.     procedure CGameApp.BeginGameMode;
  176.  
  177.     begin { BeginGameMode }
  178.         isInGameMode := TRUE;
  179.         itsGameSwitchboard.SetInGameMode(TRUE);
  180.         itsGameSwitchboard.SetBackgroundFriendly(isBkgdFriendlyInGameMode);
  181.     end; { BeginGameMode }
  182.  
  183.  
  184. {****************************************************}
  185. {}
  186. {    EndGameMode                                                                                                }
  187. {}
  188. {    Return to normal event processing.                                                                }
  189. {}
  190. {****************************************************}
  191.  
  192.     procedure CGameApp.EndGameMode;
  193.  
  194.     begin { EndGameMode }
  195.         isInGameMode := FALSE;
  196.         itsGameSwitchboard.SetInGameMode(FALSE);
  197.         itsGameSwitchboard.SetBackgroundFriendly(TRUE);
  198.     end; { EndGameMode }
  199.  
  200.  
  201. {****************************************************}
  202. {}
  203. {    GetBkgdFriendlyInGameMode                                                                            }
  204. {}
  205. {    Get the state of background friendliness in game mode.                                    }
  206. {}
  207. {****************************************************}
  208.  
  209.     function CGameApp.GetBkgdFriendlyInGameMode: Boolean;
  210.  
  211.     begin { GetBackgroundFriendly }
  212.         GetBkgdFriendlyInGameMode := isBkgdFriendlyInGameMode;
  213.     end; { GetBkgdFriendlyInGameMode }
  214.  
  215.  
  216. {****************************************************}
  217. {}
  218. {    SetBkgdFriendlyInGameMode                                                                            }
  219. {}
  220. {    Set the background friendliness in game mode.                                                }
  221. {}
  222. {****************************************************}
  223.  
  224.     procedure CGameApp.SetBkgdFriendlyInGameMode (aBkgdFriendlyInGameMode: Boolean);
  225.  
  226.     begin { SetBkgdFriendlyInGameMode }
  227.         isBkgdFriendlyInGameMode := aBkgdFriendlyInGameMode;
  228.     end; { SetBkgdFriendlyInGameMode }
  229.  
  230.  
  231. end. { CGameApp }